import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/wroks/attachment_bean.dart';
import 'package:app/src/http/bean/wroks/contract_bean.dart';
import 'package:app/src/http/bean/wroks/customers_copyInfo.dart';
import 'package:app/src/http/bean/wroks/nodelist_bean.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_card.dart';
import 'package:app/src/utils/image_path_utils.dart';

import '../../../../../http/bean/worksdo/material_requisition_bean.dart';

///审核日志
class UiNoteList {
  static Widget build(BuildContext context, List<NodeLog>? data) {
    if (StringUtils.isEmpty(data)) {
      return AppUi.getEmptyView();
    }
    List<Widget> children = [];
    children.add(
      UiBase.title(context, AppStrings.of(context).AuditLog,
          bottom: AppEdgeInsets.margin_bottom),
    ); //标题
    children.add(_table(context, data));
    var column = UiBase.column(context, children);
    var card = UiCard.build(context, column);
    return card;
  }

  static Widget _table(BuildContext context, List<NodeLog>? data) {
    List<TableRow> children = [];
    if (data != null && data.length > 0) {
      var index = 0;
      var size = data.length;
      data.forEach((element) {
        //内容
        children.add(TableRow(children: [
          Center(
            child: _text(element.InsertDatetime), //发起时间
          ),
          TableCell(child: Builder(builder: (BuildContext context) {
            index++;
            Color color_circle = Colors.blueGrey; //圆点颜色
            Color color_line = Colors.blueGrey; //垂直线条颜色
            if (index == size) {
              //最后一个是当前状态，审核日志是按时间排序的。
              color_circle = Colors.blueAccent;
            }
            //print("=======================行$index");
            var circle = Container(
              width: 13,
              height: 13,
              decoration:
                  BoxDecoration(color: color_circle, shape: BoxShape.circle),
            );
            var vertical = VerticalDivider(
              color: color_line,
              width: 3,
              thickness: 1.2,
            );
            List<Widget> children = [];
            children.add(circle);
            if (index < size) {
              var height = 45.0; //50.0;
              var value = element.Message;
              var style = AppStyle.textStyleWithCard();
              var textHeight = TextUtils.calculateTextPainter(
                          context, value!, style,
                          maxWidth: 140)
                      ?.height ??
                  30;
              height = height + textHeight;
              children.add(Container(
                child: vertical,
                height: height,
              ));
            }
            if (index >= size) {
              index = 0; //重置
            }
            return Column(
              children: children,
              mainAxisAlignment: MainAxisAlignment.start,
            );
          })),
          TableCell(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      padding: EdgeInsets.only(top: 0),
                      alignment: Alignment.topLeft,
                      width: 68,
                      child: _text(element.UserName),
                    ),
                    SizedBox(
                      child: _text(element.YwxName),
                      width: 140,
                    )
                  ],
                ), //发起审核人 发起步骤
                _text(element.Message),
              ],
            ),
          ),
        ]));
      });
    }
    var table = Table(
      defaultVerticalAlignment: TableCellVerticalAlignment.top,
      columnWidths: {
        0: FixedColumnWidth(90),
        1: FixedColumnWidth(30),
      },
      textDirection: TextDirection.ltr,
      children: children,
    );
    var width = px.screenWidth() - 40;
    return SingleChildScrollView(
      scrollDirection: Axis.horizontal,
      physics: BouncingScrollPhysics(),
      child: Container(
        width: width,
        child: table,
      ),
    );
  }

  static Widget _text(String? text, {bool isBlue = false}) {
    TextStyle? style = null;
    if (isBlue) {
      style = AppStyle.textStyleWithCardBlue();
    } else {
      style = AppStyle.textStyleWithCard();
    }
    return Text(
      text?.trim() ?? "",
      style: style,
    );
  }
}

///审核日志
class UiNoteList2 {
  static Widget build(BuildContext context, List<WFLog>? data,{String? title=null}) {
    if (StringUtils.isEmpty(data)) {
      return AppUi.getEmptyView();
    }
    List<Widget> children = [];
    if(StringUtils.isEmpty(title)){
      title=AppStrings.of(context).AuditLog;
    }
    children.add(
      UiBase.title(context, title,
          bottom: AppEdgeInsets.margin_bottom),
    ); //标题
    children.add(_table(context, data));
    var column = UiBase.column(context, children);
    var card = UiCard.build(context, column);
    return card;
  }

  static Widget _table(BuildContext context, List<WFLog>? data) {
    List<TableRow> children = [];
    if (data != null && data.length > 0) {
      var index = 0;
      var size = data.length;
      data.forEach((element) {
        //内容
        children.add(TableRow(children: [
          Center(
            child: _text(element.InsertDatetime), //发起时间
          ),
          TableCell(child: Builder(builder: (BuildContext context) {
            index++;
            Color color_circle = Colors.blueGrey; //圆点颜色
            Color color_line = Colors.blueGrey; //垂直线条颜色
            if (index == size) {
              //最后一个是当前状态，审核日志是按时间排序的。
              color_circle = Colors.blueAccent;
            }
            //print("=======================行$index");
            var circle = Container(
              width: 13,
              height: 13,
              decoration:
              BoxDecoration(color: color_circle, shape: BoxShape.circle),
            );
            var vertical = VerticalDivider(
              color: color_line,
              width: 3,
              thickness: 1.2,
            );
            List<Widget> children = [];
            children.add(circle);
            if (index < size) {
              var height = 45.0; //50.0;
              var value = element.Message;
              var style = AppStyle.textStyleWithCard();
              var textHeight = TextUtils.calculateTextPainter(
                  context, value!, style,
                  maxWidth: 140)
                  ?.height ??
                  30;
              height = height + textHeight;
              children.add(Container(
                child: vertical,
                height: height,
              ));
            }
            if (index >= size) {
              index = 0; //重置
            }
            return Column(
              children: children,
              mainAxisAlignment: MainAxisAlignment.start,
            );
          })),
          TableCell(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      padding: EdgeInsets.only(top: 0),
                      alignment: Alignment.topLeft,
                      width: 68,
                      child: _text(element.PersonName),
                    ),
                    SizedBox(
                      child: _text(element.YwxName),
                      width: 140,
                    )
                  ],
                ), //发起审核人 发起步骤
                _text(element.Message),
              ],
            ),
          ),
        ]));
      });
    }
    var table = Table(
      defaultVerticalAlignment: TableCellVerticalAlignment.top,
      columnWidths: {
        0: FixedColumnWidth(90),
        1: FixedColumnWidth(30),
      },
      textDirection: TextDirection.ltr,
      children: children,
    );
    var width = px.screenWidth() - 40;
    return SingleChildScrollView(
      scrollDirection: Axis.horizontal,
      physics: BouncingScrollPhysics(),
      child: Container(
        width: width,
        child: table,
      ),
    );
  }

  static Widget _text(String? text, {bool isBlue = false}) {
    TextStyle? style = null;
    if (isBlue) {
      style = AppStyle.textStyleWithCardBlue();
    } else {
      style = AppStyle.textStyleWithCard();
    }
    return Text(
      text?.trim() ?? "",
      style: style,
    );
  }
}